package com.lwc.cfdns.pojo.bo.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lwc.cfdns.exception.BadException;
import com.lwc.cfdns.pojo.bo.AbstractPageQuery;
import com.lwc.cfdns.pojo.entity.SystemGroup;
import com.lwc.cfdns.pojo.entity.SystemGroupData;
import com.lwc.cfdns.utils.StringUtils;
import lombok.Data;

/**
 * 组合数据查询
 *
 * @author luwc
 * @title GroupDataBO
 * @description
 * @time 2023/7/12 17:09:14
 * @version: 1.0
 */
@Data
public class GroupDataBO extends AbstractPageQuery<SystemGroupData> {
    private Long groupId = 0l;
    private String status;

    @Override
    public LambdaQueryWrapper<SystemGroupData> toQueryWrapper() {
        if (getGroupId().equals(0l)) {
            throw new BadException("groupId不能为空");
        }
        LambdaQueryWrapper<SystemGroupData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotNull(getGroupId())) {
            lambdaQueryWrapper.eq(SystemGroupData::getGroupId, getGroupId());
        }
        if (StringUtils.isNotEmpty(getStatus())) {
            lambdaQueryWrapper.eq(SystemGroupData::getStatus, getStatus());
        }
        lambdaQueryWrapper.orderByDesc(SystemGroupData::getId);
        return lambdaQueryWrapper;
    }
}
